// 小Z的毒瘤题1

#include <cstdio>
#include <algorithm>
#include <string.h>
using namespace std;

long long value[1000001];
long long flag;

long long Partition(long long data[], long long low, long long high)
{
    long long pivot = data[low];
    while (low < high)
    {
        while (low < high && data[high] >= pivot)
        {
            high--;
        }
        data[low] = data[high];
        while (low < high && data[low] <= pivot)
        {
            low++;
        }
        data[high] = data[low];
    }
    data[low] = pivot;
    return low;
}

void QuickSortDo(long long data[], long long low, long long high)
{
    if (low < high)
    {
        long long pivot = Partition(data, low, high);
        QuickSortDo(data, low, pivot - 1);
        QuickSortDo(data, pivot + 1, high);
    }
}

void QuickSort(long long data[], long long length)
{
    QuickSortDo(data, 0, length - 1);
}

int main()
{
    int T, n, m, k;
    long long sum;
    scanf("%d", &T);
    while (T--)
    {
        flag = 0;
        scanf("%d%d", &n, &m);
        memset(value, 0, sizeof(long long) * 1000001);
        for (int i = 0; i < n; i++)
        {
            scanf("%d", &k);
            for (int j = 0; j < k; j++)
            {
                scanf("%lld", &value[flag++]);
            }
        }
    }
    QuickSortDo(value, 0, flag - 1);
    sum = 0;
    for (long long i = 0; i < m; i++)
    {
        sum += value[i];
    }
}